﻿
@{
    ViewData["Title"] = "DyRemark";
    Layout = "~/Views/Shared/_Back.cshtml";
}
@model IEnumerable<IVBlog.Models.Dremark>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <h2>所有留言</h2>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>留言编号</th>
                                <th>留言内容</th>
                                <th>留言者昵称</th>
                                <th>留言者电子邮箱</th>
                                <th>留言者网站</th>
                                <th>留言日期</th>
                                <th>留言状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model)
                            {
                                <tr>
                                    <td>@item.DremarkId</td>
                                    <td class="content" 
                                        style="overflow: hidden;max-width: 110px;
                                        text-overflow: ellipsis;white-space: nowrap;">@item.Drcontent</td>
                                    <td class="name">@item.DrnickName</td>
                                    <td class="email"
                                        style="overflow: hidden;max-width: 80px;
                                        text-overflow: ellipsis;white-space: nowrap;">@item.Dremail
                                    </td>
                                    <td class="web"
                                        style="overflow: hidden;max-width: 80px;
                                        text-overflow: ellipsis;white-space: nowrap;">@item.Drweb
                                    </td>
                                    <td>@(string.Format("{0:D}", item.Drtime))</td>
                                    <td><span style="color:@(item.Drstate == 0 ? "red" : item.Drstate == 1 ? "forestgreen" : "gray")">@(item.Drstate == 0 ? "未审核" : item.Drstate == 1 ? "已审核" : "已隐藏")</span></td>
                                    <td class="td-manage">
                                        <div class="layui-btn-group">
                                            <button type="button" class="layui-btn layui-btn-sm" onclick="Seach(this)"><i class="layui-icon">&#xe654;</i>查看</button>
                                            <button type="button" class="layui-btn layui-btn-sm" style="display:@(item.Drstate == 0 ? "block" : "none")" onclick="Edit(@(item.DremarkId))"><i class="layui-icon">&#xe642;</i>审核</button>
                                            <button type="button" class="layui-btn layui-btn-sm" style="display:@(item.Drstate == 1 ? "block" : "none")" onclick="Hidden(@(item.DremarkId))"><i class="layui-icon">&#xe642;</i>隐藏</button>
                                            <button type="button" class="layui-btn layui-btn-sm" style="display:@(item.Drstate == 2 ? "block" : "none")" onclick="Block(@(item.DremarkId))"><i class="layui-icon">&#xe642;</i>恢复</button>
                                            <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" onclick="Del(@(item.DremarkId))"><i class="layui-icon">&#xe640;</i>删除</button>
                                        </div>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body">
                    <div class="page text-center">
                        <div id="pagecard">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section Scripts{
    <script>
        layui.use('laypage', function () {
            var laypage = layui.laypage;
            var totalRows = @ViewBag.totalRows;
            var totalPage = @ViewBag.totalPage;
            var pageIndex = @ViewBag.pageIndex;
            var pageSize = @ViewBag.pageSize;
            //执行一个laypage实例
            laypage.render({
                elem: 'pagecard' //注意，这里的 test1 是 ID，不用加 # 号
                , count: totalRows //数据总数，从服务端得到
                , limit: pageSize //每页显示的条数
                , curr: pageIndex
                , jump: function (obj, first) {
                    //obj包含了当前分页的所有参数，比如：
                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                    console.log(obj.limit); //得到每页显示的条数
                    //首次不执行
                    if (!first) {
                        if (pageIndex != obj.curr) {
                            location.href = "../Back/DyRemark?pageIndex=" + obj.curr + "&pageSize=" + obj.limit;
                        }
                    }
                }
            });
        });
        function Seach(obj) {
            var layer = layui.layer;
            var that = $(obj);
            var content = that.parent().parent().parent().find(".content").text()
            var email = that.parent().parent().parent().find(".email").text()
            var web = that.parent().parent().parent().find(".web").text()
            var name = that.parent().parent().parent().find(".name").text()
            layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['500px', '360px'], //宽高
                title: "留言详情",
                content: "<h4 style='color:#1E9FFF'>留言昵称</h4><p>" + name + "</p>" +
                    "<h4 style='color:#1E9FFF'>留言内容</h4><p>" + content + "</p>"+
                    "<h4 style='color:#1E9FFF'>留言者邮箱</h4><p>" + email + "</p>"+
                    "<h4 style='color:#1E9FFF'>留言者网站</h4><p>" + web + "</p>"
            });
        };
        function Edit(DremarkId) {
            var layer = layui.layer;
            layer.confirm('确定通过审核吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: 'post',
                    url: '../Back/EditDyRemark/' + DremarkId,
                    success: function () {
                        layer.msg("修改状态成功", { icon: 1 });
                        setTimeout(function () {
                            window.location.reload();
                        }, 2000);
                    },
                    error: function () {
                        layer.msg("修改失败", { icon: 2 });
                    }
                });
            }, function () {
                layer.msg('取消了审核', {
                    time: 10000, //10s后自动关闭
                    btn: ['明白了']
                });
            });
        };
        function Del(DremarkId) {
            var layer = layui.layer;
            layer.confirm('确定通过删除吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: 'post',
                    url: '../Back/DelDyRemark/' + DremarkId,
                    success: function () {
                        layer.msg("删除成功", { icon: 1 });
                        setTimeout(function () {
                            window.location.reload();
                        }, 2000);
                    },
                    error: function () {
                        layer.msg("删除失败", { icon: 2 });
                    }
                });
            }, function () {
                    layer.msg('取消了删除', {
                    time: 10000, //10s后自动关闭
                    btn: ['明白了']
                });
            });
        };
        function Hidden(DremarkId) {
            var layer = layui.layer;
            layer.confirm('确定隐藏该留言吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: 'post',
                    url: '../Back/HiddenDremark/' + DremarkId,
                    success: function () {
                        layer.msg("修改状态成功", { icon: 1 });
                        setTimeout(function () {
                            window.location.reload();
                        }, 2000);
                    },
                    error: function () {
                        layer.msg("修改失败", { icon: 2 });
                    }
                });
            }, function () {
                layer.msg('取消了隐藏', {
                    time: 10000, //10s后自动关闭
                    btn: ['明白了']
                });
            });
        };
        function Block(DremarkId) {
            var layer = layui.layer;
            layer.confirm('确定恢复该留言吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: 'post',
                    url: '../Back/BlockDremark/' + DremarkId,
                    success: function () {
                        layer.msg("修改状态成功", { icon: 1 });
                        setTimeout(function () {
                            window.location.reload();
                        }, 2000);
                    },
                    error: function () {
                        layer.msg("修改失败", { icon: 2 });
                    }
                });
            }, function () {
                layer.msg('取消了恢复', {
                    time: 10000, //10s后自动关闭
                    btn: ['明白了']
                });
            });
        };
    </script>
}



